from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-30 14:06:04.910892
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 30, Jan, 2022
Time: 14:06:10
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.9041
Nobs: 552.000 HQIC: -48.3326
Log likelihood: 6456.35 FPE: 7.76436e-22
AIC: -48.6074 Det(Omega_mle): 6.60588e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.348613 0.069734 4.999 0.000
L1.Burgenland 0.106825 0.042349 2.522 0.012
L1.Kärnten -0.110550 0.021997 -5.026 0.000
L1.Niederösterreich 0.198357 0.088580 2.239 0.025
L1.Oberösterreich 0.130889 0.087514 1.496 0.135
L1.Salzburg 0.254329 0.044766 5.681 0.000
L1.Steiermark 0.035502 0.059043 0.601 0.548
L1.Tirol 0.098046 0.047661 2.057 0.040
L1.Vorarlberg -0.071834 0.042115 -1.706 0.088
L1.Wien 0.017187 0.077923 0.221 0.825
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054507 0.151122 0.361 0.718
L1.Burgenland -0.040922 0.091776 -0.446 0.656
L1.Kärnten 0.040565 0.047670 0.851 0.395
L1.Niederösterreich -0.203399 0.191964 -1.060 0.289
L1.Oberösterreich 0.455508 0.189654 2.402 0.016
L1.Salzburg 0.283064 0.097014 2.918 0.004
L1.Steiermark 0.115862 0.127952 0.906 0.365
L1.Tirol 0.305824 0.103287 2.961 0.003
L1.Vorarlberg 0.023193 0.091269 0.254 0.799
L1.Wien -0.024640 0.168869 -0.146 0.884
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195096 0.035439 5.505 0.000
L1.Burgenland 0.090828 0.021522 4.220 0.000
L1.Kärnten -0.007362 0.011179 -0.659 0.510
L1.Niederösterreich 0.236749 0.045016 5.259 0.000
L1.Oberösterreich 0.168548 0.044475 3.790 0.000
L1.Salzburg 0.038393 0.022750 1.688 0.091
L1.Steiermark 0.025536 0.030005 0.851 0.395
L1.Tirol 0.080738 0.024221 3.333 0.001
L1.Vorarlberg 0.055484 0.021403 2.592 0.010
L1.Wien 0.117740 0.039600 2.973 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118165 0.035604 3.319 0.001
L1.Burgenland 0.043592 0.021622 2.016 0.044
L1.Kärnten -0.013775 0.011231 -1.227 0.220
L1.Niederösterreich 0.172311 0.045226 3.810 0.000
L1.Oberösterreich 0.334946 0.044682 7.496 0.000
L1.Salzburg 0.099622 0.022856 4.359 0.000
L1.Steiermark 0.109579 0.030145 3.635 0.000
L1.Tirol 0.090547 0.024334 3.721 0.000
L1.Vorarlberg 0.060693 0.021503 2.823 0.005
L1.Wien -0.015974 0.039785 -0.402 0.688
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125938 0.067188 1.874 0.061
L1.Burgenland -0.048037 0.040803 -1.177 0.239
L1.Kärnten -0.045459 0.021194 -2.145 0.032
L1.Niederösterreich 0.140935 0.085346 1.651 0.099
L1.Oberösterreich 0.167001 0.084319 1.981 0.048
L1.Salzburg 0.283776 0.043132 6.579 0.000
L1.Steiermark 0.058424 0.056887 1.027 0.304
L1.Tirol 0.155257 0.045921 3.381 0.001
L1.Vorarlberg 0.094175 0.040577 2.321 0.020
L1.Wien 0.071445 0.075078 0.952 0.341
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079816 0.052371 1.524 0.127
L1.Burgenland 0.024057 0.031805 0.756 0.449
L1.Kärnten 0.053366 0.016520 3.230 0.001
L1.Niederösterreich 0.192976 0.066525 2.901 0.004
L1.Oberösterreich 0.329922 0.065725 5.020 0.000
L1.Salzburg 0.033287 0.033620 0.990 0.322
L1.Steiermark 0.003842 0.044342 0.087 0.931
L1.Tirol 0.119809 0.035794 3.347 0.001
L1.Vorarlberg 0.066126 0.031629 2.091 0.037
L1.Wien 0.098625 0.058521 1.685 0.092
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175016 0.063409 2.760 0.006
L1.Burgenland 0.003526 0.038508 0.092 0.927
L1.Kärnten -0.065261 0.020002 -3.263 0.001
L1.Niederösterreich -0.108235 0.080546 -1.344 0.179
L1.Oberösterreich 0.212772 0.079576 2.674 0.007
L1.Salzburg 0.053245 0.040706 1.308 0.191
L1.Steiermark 0.249667 0.053687 4.650 0.000
L1.Tirol 0.498762 0.043338 11.509 0.000
L1.Vorarlberg 0.064615 0.038295 1.687 0.092
L1.Wien -0.080553 0.070855 -1.137 0.256
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156626 0.070088 2.235 0.025
L1.Burgenland -0.004189 0.042564 -0.098 0.922
L1.Kärnten 0.062202 0.022109 2.813 0.005
L1.Niederösterreich 0.181673 0.089030 2.041 0.041
L1.Oberösterreich -0.066396 0.087959 -0.755 0.450
L1.Salzburg 0.205272 0.044994 4.562 0.000
L1.Steiermark 0.139369 0.059342 2.349 0.019
L1.Tirol 0.056165 0.047903 1.172 0.241
L1.Vorarlberg 0.142837 0.042329 3.374 0.001
L1.Wien 0.129791 0.078319 1.657 0.097
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.395584 0.040887 9.675 0.000
L1.Burgenland -0.002790 0.024830 -0.112 0.911
L1.Kärnten -0.020636 0.012897 -1.600 0.110
L1.Niederösterreich 0.202851 0.051937 3.906 0.000
L1.Oberösterreich 0.240984 0.051312 4.696 0.000
L1.Salzburg 0.033476 0.026248 1.275 0.202
L1.Steiermark -0.017926 0.034618 -0.518 0.605
L1.Tirol 0.087071 0.027945 3.116 0.002
L1.Vorarlberg 0.051226 0.024693 2.074 0.038
L1.Wien 0.033821 0.045688 0.740 0.459
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035220 0.102566 0.166507 0.133290 0.093571 0.081245 0.029572 0.211944
Kärnten 0.035220 1.000000 -0.025435 0.133334 0.046792 0.086114 0.444099 -0.068397 0.093183
Niederösterreich 0.102566 -0.025435 1.000000 0.309939 0.124447 0.268210 0.067292 0.156704 0.281416
Oberösterreich 0.166507 0.133334 0.309939 1.000000 0.215003 0.292797 0.170476 0.134190 0.236617
Salzburg 0.133290 0.046792 0.124447 0.215003 1.000000 0.124513 0.089910 0.103528 0.127046
Steiermark 0.093571 0.086114 0.268210 0.292797 0.124513 1.000000 0.134341 0.105833 0.029544
Tirol 0.081245 0.444099 0.067292 0.170476 0.089910 0.134341 1.000000 0.063201 0.152102
Vorarlberg 0.029572 -0.068397 0.156704 0.134190 0.103528 0.105833 0.063201 1.000000 -0.004776
Wien 0.211944 0.093183 0.281416 0.236617 0.127046 0.029544 0.152102 -0.004776 1.000000